<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../jqgrid.jsp"></jsp:include>

</head>
<script type="text/javascript">
var holdId="";
function fillData(formid){
	formid.find("#holdId").val(holdId);
}
function queryAllRooms() {
	var url = "queryAllRooms.action";
	var types = "";
	$.ajax({
		type : "POST",
		url : url,
		dataType : "json",
		async : false,
		success : function(data) {
			$.each(data, function(i, item) {
				types += item["id"] + ":"+item["bNumber"]+""+item["roomCode"] + ";";
			});
		}
	});
	return types.substring(0, types.lastIndexOf(";"));
} 
	$(document).ready(function() {
		jQuery("#householdlist").jqGrid({
			url : 'queryHousehold.action',
			autowidth : true,
			datatype : "json",
			colNames : [ 'id','房子','房子', '住户姓名', '性别', '电话','常住人数','交房时间','是否入住','入住时间','是否已办理房产证','是否开发票'],
			colModel : [ {
				name : 'id',
				index : 'id',
				width : 55,
				editable : false,
				hidden:true
			}, {
				name : 'roomId',
				index : 'roomId',
				width : 55,
				hidden:true,
				editable : true,
				align : "center",
				edittype:"select",
				editoptions:{
					value:queryAllRooms
				},
				editrules:{
					required:true,
					edithidden:true
				},
			},{
				name : 'roomName',
				index : 'roomName',
				align : "center",
				width : 50,
				editable : false,
				searchoptions :{
					sopt:['cn','nc']
				}
			},{
				name : 'name',
				index : 'name',
				align : "center",
				width : 50,
				editable : true,
				editrules:{
					required:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'sex',
				index : 'sex',
				width : 20,
				editable : true,
				align : "center",
				edittype : "select",
				editoptions : {
					value : '1:女;0:男'
				},
				formatter : function(cellvalue, options, row) {
					if (cellvalue == 1) {
						return "女";
					} else {
						return "男";
					}
				},
					stype:'select',
				searchoptions :{
					sopt:['eq','ne'],
					dataUrl:"<%=request.getContextPath()%>/jsp/sex.jsp"
				}
			}, {
				name : 'phone',
				index : 'phone',
				width : 80,
				align : "center",
				editable : true,
				editrules:{
					required:true,
					integer:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'number',
				index : 'number',
				width : 80,
				align : "center",
				editable : true,
				editrules:{
					required:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'acceptTime',
				index : 'acceptTime',
				width : 80,
				align : "center",
				editable : true,
				formatter:"date",
				editrules:{
					required:true,
					date:true
				},
				formatoptions:{"newformat":"Y-m-d"},
				 editoptions: {
		              size: 10, 
		              maxlengh: 10,
		              dataInit: function(element) {
		                  $(element).datepicker({ dateFormat: 'yy-mm-dd'});
		              }
		          },
		          searchoptions:{dataInit:datePick,sopt:['le','ge']}
			}, {
				name : 'hasLive',
				index : 'hasLive',
				width : 80,
				align : "center",
				editable : true,
				edittype : "select",
				editoptions : {
					value : 'true:是;false:否'
				},
				formatter : function(cellvalue, options, row) {
					if (cellvalue == true) {
						return "是";
					} else {
						return "否";
					}
				},
				stype:'select',
				searchoptions :{
					sopt:['eq','ne'],
					dataUrl:"<%=request.getContextPath()%>/jsp/trueOrFalse.jsp"
				}
			}, {
				name : 'liveTime',
				index : 'liveTime',
				width : 80,
				align : "center",
				editable : true,
				formatter:"date",
				editrules:{
					required:true,
					date:true
				},
				formatoptions:{"newformat":"Y-m-d"},
				 editoptions: {
		              size: 10, 
		              maxlengh: 10,
		              dataInit: function(element) {
		                  $(element).datepicker({ dateFormat: 'yy-mm-dd'});
		              }
		          },
		          searchoptions:{dataInit:datePick,sopt:['le','ge']}
			}, {
				name : 'hasCertificate',
				index : 'hasCertificate',
				width : 80,
				align : "center",
				editable : true,
				edittype : "select",
				editoptions : {
					value : 'true:是;false:否'
				},
				formatter : function(cellvalue, options, row) {
					if (cellvalue == true) {
						return "是";
					} else {
						return "否";
					}
				},
				stype:'select',
				searchoptions :{
					sopt:['eq','ne'],
					dataUrl:"<%=request.getContextPath()%>/jsp/trueOrFalse.jsp"
				}				
			}, {
				name : 'hasBilling',
				index : 'hasBilling',
				width : 80,
				align : "center",
				editable : true,
				edittype : "select",
				editoptions : {
					value : 'true:是;false:否'
				},
				formatter : function(cellvalue, options, row) {
					if (cellvalue == true) {
						return "是";
					} else {
						return "否";
					}
				},
				stype:'select',
				searchoptions :{
					sopt:['eq','ne'],
					dataUrl:"<%=request.getContextPath()%>/jsp/trueOrFalse.jsp"
				}
			}],
			onSelectRow:function(rowid,status){
				var data = $("#householdlist").getRowData(rowid);
				 jQuery("#houseapprovelist").setGridParam({
					 url:"queryHouseApproval.action?holdId="+data.id
					 }).trigger("reloadGrid"); 
				 holdId=data.id;
			},
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			pager : '#householdgridPager',
			sortname : 'id',
			viewrecords : true,
			jsonReader : {
				repeatitems : false
			},
			sortorder : "desc",
			caption : "业主列表",
			editurl:"editHousehold.action"
		});
		jQuery("#householdlist").jqGrid('navGrid', '#householdgridPager', {
			edit : true,
			add : true,
			del : false
		}, {}, {}, {},{multipleSearch:true});
		
		
		
		
		
		
		
		
		
		jQuery("#houseapprovelist").jqGrid({
			//url : 'queryHousehold.action',
			autowidth : true,
			datatype : "json",
			colNames : [ 'id','业主','墙体情况','渗水情况', '门窗情况', '电路情况', '水路情况','面积情况','时间情况','备注'],
			colModel : [ {
				name : 'id',
				index : 'id',
				width : 55,
				editable : false,
				hidden:true
			},{
				name : 'holdId',
				index : 'holdId',
				width : 55,
				hidden:true,
				editable : true,
				editrules:{
					required:true
				},
			}, {
				name : 'wall',
				index : 'wall',
				width : 55,
				editable : true,
				align : "center",
				editrules:{
					required:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			},{
				name : 'oozingWater',
				index : 'oozingWater',
				align : "center",
				width : 50,
				editable : true,
				editrules:{
					required:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			},{
				name : 'doorWindow',
				index : 'doorWindow',
				align : "center",
				width : 50,
				editable : true,
				editrules:{
					required:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'electricity',
				index : 'electricity',
				width : 20,
				editable : true,
				align : "center",
				editrules:{
					required:true,
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'water',
				index : 'water',
				width : 80,
				align : "center",
				editable : true,
				editrules:{
					required:true,
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'area',
				index : 'area',
				width : 80,
				align : "center",
				editable : true,
				editrules:{
					required:true
				},
				searchoptions :{
					sopt:['cn','nc']
				}
			}, {
				name : 'approvalDate',
				index : 'approvalDate',
				width : 80,
				align : "center",
				editable : true,
				formatter:"date",
				editrules:{
					required:true,
					date:true
				},
				formatoptions:{"newformat":"Y-m-d"},
				 editoptions: {
		              size: 10, 
		              maxlengh: 10,
		              dataInit: function(element) {
		                  $(element).datepicker({ dateFormat: 'yy-mm-dd'});
		              }
		          },
		          searchoptions:{dataInit:datePick,sopt:['le','ge']}
			}, {
				name : 'remark',
				index : 'remark',
				width : 80,
				align : "center",
				editable : true,
				searchoptions :{
					sopt:['cn','nc']
				}
			}],
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			pager : '#houseapprovegridPager',
			sortname : 'id',
			viewrecords : true,
			jsonReader : {
				repeatitems : false
			},
			sortorder : "desc",
			caption : "验收记录",
			editurl:"editHouseApproval.action",
		});
		 jQuery("#houseapprovelist").jqGrid('navGrid', '#houseapprovegridPager', {
			edit : true,
			add : true,
			del : true,
			search:false
		}, {}, {afterShowForm : fillData});
	});
	datePick = function(elem)
	{
	   jQuery(elem).datepicker();
	}
</script>
<body>
	<div align="center">
		<table id="householdlist"></table>
		<div id="householdgridPager"></div>
		<table id="houseapprovelist"></table>
		<div id="houseapprovegridPager"></div>
	</div>
</body>
</html>